package com.temi.iot.exception;

import org.springframework.http.HttpStatus;

/**
 * @author yanghengchao
 * @Description 所有业务异常的枚举
 */
public enum BizExceptionEnum {

    /**
     * 正常结果
     */
    SUCCESS(HttpStatus.OK, "操作成功", 1000),
    SUCCESS_DATA(HttpStatus.OK, "操作成功", 1001),
    PAGE_NULL(HttpStatus.OK, "暂无数据", 1002),
    PAGE(HttpStatus.OK, "操作成功", 1003),

    /**
     * 账户问题
     */
    USER_ALREADY_REG(HttpStatus.OK, "该用户已经注册", 2001),
    NO_THIS_USER(HttpStatus.OK, "没有此用户", 2002),
    LOGIN_ERROR(HttpStatus.OK, "账户或者密码错误", 2003, LoginError.class),
    ACCOUNT_FREEZED(HttpStatus.OK, "账号被冻结", 2004),
    OLD_PWD_NOT_RIGHT(HttpStatus.OK, "原密码不正确", 2005),
    TWO_PWD_NOT_MATCH(HttpStatus.OK, "两次输入密码不一致", 2006),
    TWO_COMMIT_RESEARCH(HttpStatus.OK,"该手机号码已提交审核，请勿重复提交",2017),
    USER_COMMIT_RESEARCH(HttpStatus.OK,"该用户为待审核状态，请勿重复提交",2017),
    USER_NULL(HttpStatus.OK, "该用户不存在", 2111),
    EXIST_MEMBER(HttpStatus.OK, "角色删除失败,尚有用户属于此角色", 2112),

    /**
     * 权限和数据问题
     */
    DB_RESOURCE_NULL(HttpStatus.OK, "数据库中没有该资源", 2007),
    NO_PERMITION(HttpStatus.OK, "权限异常", 2008),
    REQUEST_INVALIDATE(HttpStatus.OK, "请求数据格式不正确", 2009),
    INVALID_KAPTCHA(HttpStatus.OK, "验证码不正确", 2010),
    ASK_LIMIT(HttpStatus.OK,"操作频繁,稍后再试",2011),
    USER_UNCHECK(HttpStatus.OK,"用户未审核",2012),
    USER_UNAPPLY_TYPE(HttpStatus.OK,"用户没有发布设备权限",2013),
    USER_UNDISABLE_TYPE(HttpStatus.OK,"用户已被禁用",2014),
    USER_UNREVIEW_TYPE(HttpStatus.OK,"用户未通过出租权限",2015),
    RECENTDEAL_NUM(HttpStatus.OK,"超出限定数量",2016),
    NO_REPEAT(HttpStatus.OK,"请勿添加两条重复数据",2018),
    ERRPOR_NUM(HttpStatus.OK,"数据不符合规定",2019),
    ERRPOR_OVER_TIME(HttpStatus.OK,"登陆超时",2019),
    /**
     * 文件上传
     */
    FILE_READING_ERROR(HttpStatus.OK, "FILE_READING_ERROR!", 3001),
    FILE_NOT_FOUND(HttpStatus.OK, "FILE_NOT_FOUND!", 3002),
    UPLOAD_ERROR(HttpStatus.OK, "上传图片出错", 3003),

    /**
     * 参数检验错误
     */
    VALIDA_ERROR(HttpStatus.OK, 4000),

    /**
     * 数据库操作异常
     */
    DB_INSERT_ERROR(HttpStatus.OK, 4001),
    DB_UPDATE_ERROR(HttpStatus.OK, 4002),
    DB_DELETE_ERROR(HttpStatus.OK, 4003),
    DB_ATTRIDUTE_ERROR(HttpStatus.OK, "bean参数错误",4004),

    /**
     * 错误的请求
     */
    REQUEST_NULL(HttpStatus.OK, "请求有错误", 9000),
    SERVER_ERROR(HttpStatus.OK, "服务器异常", 9001),
    /**
     * REDIS 链接错误
     */
    REDIS_NOT_CONNECTION(HttpStatus.OK, "服务器链接错误!", 9002),
    /**
     * 字典创建错误
     */
    ERROR_WRAPPER_FIELD(HttpStatus.OK, "字典创建错误!", 9003),
    ERROR_CREATE_DICT(HttpStatus.OK, "字典创建错误!", 9004),
    NOT_FOUND(HttpStatus.OK, "找不到资源!", 9005);

    BizExceptionEnum(HttpStatus status, String message, int code) {
        this.status = status;
        this.msg = message;
        this.code = code;
        this.ex = BussinessException.class;
    }

    BizExceptionEnum(HttpStatus status, String message, int code, Class ex) {
        this.status = status;
        this.msg = message;
        this.code = code;
        this.ex = ex;
    }

    BizExceptionEnum(HttpStatus status, int code) {
        this.code = code;
        this.status = status;
        this.ex = BussinessException.class;
    }

    private HttpStatus status;
    private String msg;
    private int code;
    private Class ex;


    public HttpStatus getStatus() {
        return status;
    }

    public void setStatus(HttpStatus status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public Class getEx() {
        return ex;
    }

    public void setEx(Class ex) {
        this.ex = ex;
    }

    public BizExceptionEnum msg(String msg) {
        this.msg = msg;
        return this;
    }
}
